%zhp 6/15改
%by clq
%2021/6/12
function[i_R,profits_R,EYI,EYin,ProfitPart]=round_robin(j_all,N)
addpath functions;
global P J I ci cI r LAMBDA CURRENT PIEs EYin ProfitPart EYI
patient_number=size(j_all,2);
N=min(patient_number,N);%N不能超过给了病种的病人数。
ProfitPart=zeros(3,N);
EYI=zeros(1,N);
EYin=zeros(1,N);

genPoisson(N);
genPIE(N);
%j_all is the given order of patient types


S=zeros(I,J);
i_R=zeros(1,N);
%Step1:find the optimal slot for each patient
for i=1:N
    CURRENT=i;
    i_R(1,CURRENT)=mod(CURRENT-1,I)+1; 

%Step2:find the profit after each patient is assigned
    j=j_all(CURRENT);
    S(i_R(1,CURRENT),j)=S(i_R(1,CURRENT),j)+1;
       Q = findQ(S); 
       R = findR(Q);
       profits_R(CURRENT)=function_fQR(Q,R);
end
return




